<template>
	<view class="addNotice">
		<view class="uploadModule">
			<view class="rich">
				<view class="richTitle">
					<textarea placeholder-class="font14" v-model.trim="title" :disabled="preIdentity.userType==2 || preIdentity.userState!=1" class="bold font18" maxlength="30" auto-height placeholder="输入标题(30个字符)"></textarea>
				</view>
				<view class="richCon">
					<textarea class="font16" placeholder-class="font14" :disabled="preIdentity.userType==2 || preIdentity.userState!=1" v-model.trim="content" cols="30" rows="10" placeholder="请输入详细内容"></textarea>
				</view>
				<!-- 是否置顶 -->
				<view class="flex alignCenter justConBetween">
					<view class="">是否置顶</view>
					<switch class="switch" style="transform:scale(0.7)" :disabled="preIdentity.userType==2 || preIdentity.userState!=1" :checked="isTop" @change="changeTop"/>
				</view>
			</view>
		</view>
		<view class="fixedBottomBtn" v-if="(preIdentity.userType!=2 && preIdentity.userState==1)" @click="submitClick"><i class="iconfont icon-fabu"></i>发布</view>
	</view>
</template>

<script>
	import { addNotice } from "@/api/send.js"
	import { uploadFile,chooseImg} from "@/utils/common.js"
	export default {
		data() {
			return {
				title:'',
				content:'',
				groupId:'',
				isTop:false,
				notice:'',
				preIdentity:''
			}
		},
		onLoad(option) {
			this.groupId=option.id || ''
			this.notice=(option.notice?JSON.parse(option.notice):'')
			this.preIdentity=(option.preIdentity?JSON.parse(option.preIdentity):'')
			console.log('notice',this.notice,this.preIdentity,option)
			if(this.notice){
				this.title=this.notice.title
				this.content=this.notice.content
				this.isTop=this.notice.isTop
			}
		},
		onShow() {
			
		},
		onReady() {
			if(this.notice){
				uni.setNavigationBarTitle({
					title:'公告详情'
				})
			}
		},
		onUnload() {
			
		},
		methods: {
			// 修改置顶状态
			changeTop(e){
				this.isTop=e.detail.value
			},
			submitClick() {
				if(!this.title){
					uni.showToast({
						icon:'none',
						title:'请输入标题！'
					})
					return
				}
				if(!this.content){
					uni.showToast({
						icon:'none',
						title:'请输入内容！'
					})
					return
				}
				uni.showLoading({
					title:'提交中',
					mask:true
				})
				let param={
					id:this.notice?this.notice.id:'',
					teamId:this.groupId,
					title:this.title,
					content:this.content,
					isTop:this.isTop
				}
				addNotice(param).then((res)=>{
					if(res.code==100000){
						uni.navigateBack({
							delta:1
						})
					}
					uni.hideLoading()
				}).catch((err)=>{uni.hideLoading()})
				
			},
		}
	}
</script>

<style scoped lang="scss">
@import "@/static/public.scss";
.addNotice{
	padding:0 0 120rpx;
}
.rich{
	padding: 50rpx 30rpx 0;
	box-sizing: border-box;
	.richTitle{
		textarea{
			width: 100%;
		}
		padding: 20rpx 0;
		border-bottom: 1px solid $bordercolor;
	}
	.richCon{
		textarea{
			width: 100%;
			padding: 20rpx 0;
			box-sizing: border-box;
		}
	}
	.labelItem{
		margin-right: 50rpx;
	}
}
::v-deep .uni-switch-input-checked{
	background-color:$colorMain !important;
	border-color:$colorMain !important;
}
</style>
